package orest.front.market;

import java.io.IOException;
import java.rmi.ServerException;
import java.sql.Connection;
import java.sql.Date;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import orest.front.achieve.AchieveHandler;
import orest.front.market.MarketHandler;

import net.ssta.core.base.ServletBase;
import net.ssta.core.db.DBConnectionProvider;
import net.ssta.core.db.PagingInfo;
import net.ssta.core.db.Record;
import net.ssta.core.db.RecordSet;
import net.ssta.core.web.RequestKit;
import net.ssta.core.util.DateUtility;

import net.ssta.common.Constants;
import net.ssta.common.LoginUser;
import net.ssta.core.util.DateUtility;


/**
 @author zhanggk
 
 用户注册、用户中心等相关信息维护
 **/
public class MarketServlet  extends ServletBase{

    protected void defaultAction(HttpServletRequest request,HttpServletResponse response) throws IOException
    {
		//技术市场
		System.out.println("in MarketServlet");
    	Connection conn = null;
    	try {
    		conn = DBConnectionProvider.getConnection(Constants.JNDI_SSTA);
    	}catch(SQLException sqle){
    		System.out.println("获取数据库连接出错。");
    	}
    	RequestKit requestKit=new RequestKit(request);

    	try {
	    	//默认转向用户中心首页
	    	forward("/membercenter/usecenter.jsp");
	    	
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println(e.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println(e.toString());
		}finally{
			//关闭数据库链接
			if (conn != null)
	        {
				try
	            {
	                conn.close();
	            }catch (SQLException e){
	                e.printStackTrace();
	            }
	        }
		}
		
    }
	
	/**
     * 添加技术需求信息
     * 
     * @param request
     * @param response
     */
    public void addTechneed(HttpServletRequest request,HttpServletResponse response)
    {
    	Connection conn = null;
    	RequestKit requestKit=new RequestKit(request);
    	String forwardurl = "";
    	
    	try {
    		//获取数据库链接
    		conn = DBConnectionProvider.getConnection(Constants.JNDI_SSTA);
    	
	    	//从页面上获取技术需求相关内容
	    	Record record = requestKit.getRecordWithPrefix("TECHNEED_");
	    	
	    	//添加用户信息表
	    	record.setEntityName("T_TECHNEED");
	    	record.setConnection(conn);
	    	record.setPrimaryKey("ID");
	    	
	    	record.addData("SUBMITDATE", DateUtility.getCurrentDateTime());//提交日期为当前日期
//	    	Calendar validdate = Calendar.getInstance();
//	    	validdate.add(Calendar.MONTH, 1);
//	    	record.addData("VALID",DateUtility.getStrDate(validdate.getTimeInMillis(), 3));
	    	String userid = LoginUser.getUserId();
	    	record.addData("USERID", LoginUser.getUserId()); 		//获取登录人员uuid
	    	record.addData("IFCHECK", "0");		//是否通过审核，默认设置为0，未审核
	    	record.addData("CHANNELSHOW", "0");	//是否在栏目页推荐位显示，默认设置为0，不推荐
	    	record.addData("HOMEPAGESHOW", "0");//是否在首页推荐位显示，默认设置为0，不推荐
	    	
	    	//数据库中插入技术需求信息
	    	Record recordresult = record.create();
	    	
	    	//添加成功后返回用户中心技术需求列表页面
	    	//forwardurl = "/market?method=techneedList";
	    	//forward(forwardurl);
	    	this.sendRedirectByStyle(request.getContextPath()+"/membercenter/market?method=techneedList");
	    	//response.sendRedirect(request.getContextPath()+"/membercenter/market?method=techneedList");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch(SQLException s){
			s.printStackTrace();
		}finally{
			//释放数据库连接
			if (conn != null)
	        {
				try
	            {
	                conn.close();
	            }catch (SQLException e){
	                e.printStackTrace();
	            }
	        }
		}	
    }
    
    
    /**
     * 添加自荐项目
     * 
     * @param request
     * @param response
     */
    public void addSelloneself(HttpServletRequest request,HttpServletResponse response)
    {
    	Connection conn = null;
    	RequestKit requestKit=new RequestKit(request);
    	String forwardurl = "";
    	
    	try {
    		//获取数据库链接
    		conn = DBConnectionProvider.getConnection(Constants.JNDI_SSTA);
    	
	    	//从页面上获取自荐项目相关内容
	    	Record record = requestKit.getRecordWithPrefix("SELL_");
	    	
	    	//添加自荐项目信息
	    	record.setEntityName("T_SELLONESELF");
	    	record.setConnection(conn);
	    	record.setPrimaryKey("ID");
	    	
	    	record.addData("SUBMITDATE", DateUtility.getCurrentDateTime());//提交日期为当前日期
	    	record.addData("USERID", LoginUser.getUserId()); 		//获取登录人员id
	    	record.addData("IFCHECK", "0");		//是否通过审核，默认设置为0，未审核
	    	record.addData("CHANNELSHOW", "0");	//是否在栏目页推荐位显示，默认设置为0，不推荐
	    	record.addData("HOMEPAGESHOW", "0");//是否在首页推荐位显示，默认设置为0，不推荐
	    	
	    	//数据库中插入自荐项目信息
	    	Record recordresult = record.create();
	    	
	    	//添加成功后返回用户中心自荐项目列表页面
	    	//forwardurl = "/market?mthod=selloneselfList";
	    	//forward(forwardurl);
	    	 response.sendRedirect(request.getContextPath()+"/membercenter/market?method=selloneselfList");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch(SQLException s){
			s.printStackTrace();
		}finally{
			//释放数据库连接
			if (conn != null)
	        {
				try
	            {
	                conn.close();
	            }catch (SQLException e){
	                e.printStackTrace();
	            }
	        }
		}	
    }
    
    /**
     * 添加投融资项目信息
     * 
     * @param request
     * @param response
     */
    public void addInvest(HttpServletRequest request,HttpServletResponse response)
    {
    	Connection conn = null;
    	RequestKit requestKit=new RequestKit(request);
    	String forwardurl = "";
    	
    	try {
    		//获取数据库链接
    		conn = DBConnectionProvider.getConnection(Constants.JNDI_SSTA);
    	
	    	//从页面上获取投融资项目相关内容
	    	Record record = requestKit.getRecordWithPrefix("INVEST_");
	    	
	    	//添加投融资项目
	    	record.setEntityName("T_INVESTANDFINANCE");
	    	record.setConnection(conn);
	    	record.setPrimaryKey("ID");
	    	
	    	record.addData("SUBMITDATE", DateUtility.getCurrentDateTime());//提交日期为当前日期
	    	//处理数字类型的字段，手工转为数字型
	    	record.addData("INVESTSUMEXPECT", Integer.valueOf(record.getString("INVESTSUMEXPECT", "0")));
	    	record.addData("INVESTEDSUM", Integer.valueOf(record.getString("INVESTEDSUM", "0")));
	    	record.addData("FIXEDYEAR", Integer.valueOf(record.getString("FIXEDYEAR", "0")));
	    	
	    	record.addData("USERID", LoginUser.getUserId()); 		//获取登录人员id
	    	record.addData("IFCHECK", "0");		//是否通过审核，默认设置为0，未审核
	    	record.addData("CHANNELSHOW", "0");	//是否在栏目页推荐位显示，默认设置为0，不推荐
	    	record.addData("HOMEPAGESHOW", "0");//是否在首页推荐位显示，默认设置为0，不推荐
	    	
	    	//数据库中插入投融资项目信息
	    	Record recordresult = record.create();
	    	
	    	//添加成功后返回用户中心投融资项目列表页面
	    	//forwardurl = "/market?method=investList";
	    	//forward(forwardurl);
	    	response.sendRedirect(request.getContextPath()+"/membercenter/market?method=investList");
	    	
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch(SQLException s){
			s.printStackTrace();
		}finally{
			//释放数据库连接
			if (conn != null)
	        {
				try
	            {
	                conn.close();
	            }catch (SQLException e){
	                e.printStackTrace();
	            }
	        }
		}
    }
    
    
    /**
     * 修改自荐项目信息
     * 只有在未审核状态、审核不通过状态前台用户才能修改投融资项目信息，审核通过的信息不能修改。
     * 
     * @param request
     * @param response
     */
    public void updateTechneed(HttpServletRequest request,HttpServletResponse response)
    {
    	Connection conn = null;
    	RequestKit requestKit=new RequestKit(request);
    	String forwardurl = "";
    	
    	try {
    		//获取数据库链接
    		conn = DBConnectionProvider.getConnection(Constants.JNDI_SSTA);
    		
    		//从页面上获取技术需求ID
    		String techneedid = requestKit.getParameter("uuid", "");
	    	//从页面上获取技术需求相关内容
	    	Record record = requestKit.getRecordWithPrefix("TECHNEED_");
	    	
	    	//修改投融资项目
	    	record.setEntityName("T_TECHNEED");
	    	record.setConnection(conn);
	    	record.setPrimaryKey("ID");
	    	record.addData("ID", techneedid);
	    	
	    	record.addData("SUBMITDATE", DateUtility.getCurrentDateTime());//提交日期为当前日期
	    	record.addData("USERID", LoginUser.getUserId()); 		//获取登录人员id
	    	record.addData("IFCHECK", "0");		//将审核标志位设置为未审核。其他标志位不变。
	    	
	    	//数据库中修改投融资项目信息
	    	record.update();
	    	
	    	//添加成功后返回用户中心投融资项目列表页面
	    	//forwardurl = "/market?method=techneedList";
	    	//forward(forwardurl);
	    	
	    	response.sendRedirect(request.getContextPath()+"/membercenter/market?method=techneedList");
	    	
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch(SQLException s){
			s.printStackTrace();
		}finally{
			//释放数据库连接
			if (conn != null)
	        {
				try
	            {
	                conn.close();
	            }catch (SQLException e){
	                e.printStackTrace();
	            }
	        }
		}
    }
    
    
    
    /**
     * 修改自荐项目信息
     * 只有在未审核状态、审核不通过状态前台用户才能修改投融资项目信息，审核通过的信息不能修改。
     * 
     * @param request
     * @param response
     */
    public void updateSelloneself(HttpServletRequest request,HttpServletResponse response)
    {
    	Connection conn = null;
    	RequestKit requestKit=new RequestKit(request);
    	String forwardurl = "";
    	
    	try {
    		//获取数据库链接
    		conn = DBConnectionProvider.getConnection(Constants.JNDI_SSTA);
    		
    		//从页面上获取投融资项目ID
    		String selloneselfid = requestKit.getParameter("uuid", "");
	    	//从页面上获取投融资项目相关内容
	    	Record record = requestKit.getRecordWithPrefix("SELL_");
	    	
	    	//修改投融资项目
	    	record.setEntityName("T_SELLONESELF");
	    	record.setConnection(conn);
	    	record.setPrimaryKey("ID");
	    	record.addData("ID", selloneselfid);
	    	
	    	record.addData("SUBMITDATE", DateUtility.getCurrentDateTime());//提交日期为当前日期
	    	record.addData("USERID", LoginUser.getUserId()); 		//?????????????????????????????????????????????
	    	record.addData("IFCHECK", "0");		//将审核标志位设置为未审核。其他标志位不变。
	    	
	    	//数据库中修改投融资项目信息
	    	record.update();
	    	
	    	//添加成功后返回用户中心投融资项目列表页面
	    	//forwardurl = "/market?method=selloneselfList";
	    	//forward(forwardurl);
	    	response.sendRedirect(request.getContextPath()+"/membercenter/market?method=selloneselfList");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch(SQLException s){
			s.printStackTrace();
		}finally{
			//释放数据库连接
			if (conn != null)
	        {
				try
	            {
	                conn.close();
	            }catch (SQLException e){
	                e.printStackTrace();
	            }
	        }
		}
    }
    
    
    /**
     * 修改投融资项目信息
     * 只有在未审核状态、审核不通过状态前台用户才能修改投融资项目信息，审核通过的信息不能修改。
     * 
     * @param request
     * @param response
     */
    public void updateInvest(HttpServletRequest request,HttpServletResponse response)
    {
    	Connection conn = null;
    	RequestKit requestKit=new RequestKit(request);
    	String forwardurl = "";
    	
    	try {
    		//获取数据库链接
    		conn = DBConnectionProvider.getConnection(Constants.JNDI_SSTA);
    		
    		//从页面上获取投融资项目ID
    		String investprojectid = requestKit.getParameter("uuid", "");
	    	//从页面上获取投融资项目相关内容
	    	Record record = requestKit.getRecordWithPrefix("INVEST_");
	    	
	    	//修改投融资项目
	    	record.setEntityName("T_INVESTANDFINANCE");
	    	record.setConnection(conn);
	    	record.setPrimaryKey("ID");
	    	record.addData("ID", investprojectid);
	    	
	    	record.addData("SUBMITDATE", DateUtility.getCurrentDateTime());//提交日期为当前日期
	    	record.addData("USERID", LoginUser.getUserId()); 		//?????????????????????????????????????????????
	    	record.addData("IFCHECK", "0");		//将审核标志位设置为未审核。其他标志位不变。
	    	
	    	//数据库中修改投融资项目信息
	    	record.update();
	    	
	    	//添加成功后返回用户中心投融资项目列表页面
	    	//forwardurl = "/market?method=investList";
	    	//forward(forwardurl);
	    	response.sendRedirect(request.getContextPath()+"/membercenter/market?method=investList");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch(SQLException s){
			s.printStackTrace();
		}finally{
			//释放数据库连接
			if (conn != null)
	        {
				try
	            {
	                conn.close();
	            }catch (SQLException e){
	                e.printStackTrace();
	            }
	        }
		}
    }
    
    /**
     * 技术市场首页，展现三类信息
     * 
     * @param request
     * @param response
     */
    public void marketIndex(HttpServletRequest request,HttpServletResponse response)
    {
    	
			try {
				
				RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		        PagingInfo pagingInfo = new PagingInfo(request, 10, "^(?!.*(result)|(LTPAToken)).*$");
		        
		        MarketHandler markethandler = new MarketHandler();
		        RecordSet techneedSet = markethandler.getTechneedList(requestKit, pagingInfo);
		        RecordSet selloneselfSet = markethandler.getSelloneselfList(requestKit, pagingInfo);
		        RecordSet investSet = markethandler.getInvestList(requestKit, pagingInfo);
		        
		        request.setAttribute("techneedSet", techneedSet);
		        request.setAttribute("selloneselfSet", selloneselfSet);
		        request.setAttribute("investSet", investSet);
		        request.setAttribute("pagingInfo", pagingInfo);
		        
		    	forward("/membercenter/market/marketindex.jsp");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ServletException ex){
				ex.printStackTrace();
			}
		
    }
    
    /**
     * 获取用户技术需求列表
     * 
     * @param request
     * @param response
     */
    public void techneedList(HttpServletRequest request,HttpServletResponse response)
    {
    	
			try {
				
				RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		        PagingInfo pagingInfo = new PagingInfo(request, 10, "^(?!.*(result)|(LTPAToken)).*$");
		        
		        MarketHandler markethandler = new MarketHandler();
		        RecordSet techneedSet = markethandler.getTechneedList(requestKit, pagingInfo);
		        
		        request.setAttribute("techneedSet", techneedSet);
		        request.setAttribute("pagingInfo", pagingInfo);
		        
		    	forwardByStyle("/membercenter/market/techneedList.jsp");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ServletException ex){
				ex.printStackTrace();
			}
		
    }
    
    /**
     * 获取用户自荐项目列表
     * 
     * @param request
     * @param response
     */
    public void selloneselfList(HttpServletRequest request,HttpServletResponse response)
    {
    	
    	try {
			
			RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
	        PagingInfo pagingInfo = new PagingInfo(request, 10, "^(?!.*(result)|(LTPAToken)).*$");
	        
	        MarketHandler markethandler = new MarketHandler();
	        RecordSet selloneselfSet = markethandler.getSelloneselfList(requestKit, pagingInfo);
	        
	        request.setAttribute("selloneselfSet", selloneselfSet);
	        request.setAttribute("pagingInfo", pagingInfo);
	        
	    //	forward("/membercenter/market/selloneselfList.jsp");
	    	this.forwardByStyle("/membercenter/market/selloneselfList.jsp");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServletException ex){
			ex.printStackTrace();
		}
    }
    
    /**
     * 获取用户投融资项目列表
     * 
     * @param request
     * @param response
     */
    public void investList(HttpServletRequest request,HttpServletResponse response)
    {
    	
    	try {
			
			RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
	        PagingInfo pagingInfo = new PagingInfo(request, 10, "^(?!.*(result)|(LTPAToken)).*$");
	        
	        MarketHandler markethandler = new MarketHandler();
	        RecordSet investSet = markethandler.getInvestList(requestKit, pagingInfo);
	        
	        request.setAttribute("investSet", investSet);
	        request.setAttribute("pagingInfo", pagingInfo);
	        
	    	this.forwardByStyle("/membercenter/market/investList.jsp");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServletException ex){
			ex.printStackTrace();
		}
    }
    
    
    /**
     * 根据uuid获取指定技术需求的详细信息
     * 
     * @param request
     * @param response
     */
    public void techneedShow(HttpServletRequest request,HttpServletResponse response)
    {
    	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        MarketHandler markethandler = new MarketHandler();
        String uuid = requestKit.getParameter("uuid", "");
        
        Record techneedInfo = markethandler.getTechneedById(uuid);
        request.setAttribute("techneedInfo", techneedInfo);
        
        Map fildOptionMap = new HashMap();
        //RecordSet newEnerClass = markethandler.getFildOption("common","NewEnergyClass");
        RecordSet newEnerClass = AchieveHandler.getNewEnergyClassList();
        request.setAttribute("newenergyclass", newEnerClass);
        
        try{
        	forward("/membercenter/market/techneedInfo.jsp");
        } catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServletException ex){
			ex.printStackTrace();
		}
    }
    
    /**
     * 根据uuid获取指定自荐项目的详细信息
     * 
     * @param request
     * @param response
     */
    public void selloneselfShow(HttpServletRequest request,HttpServletResponse response)
    {
    	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        MarketHandler markethandler = new MarketHandler();
        String uuid = requestKit.getParameter("uuid", "");
        
        Record selloneselfInfo = markethandler.getSelloneselfById(uuid);
        request.setAttribute("selloneselfinfo", selloneselfInfo);
        
        Map fildOptionMap = new HashMap();
        //RecordSet newEnerClass = markethandler.getFildOption("common","NewEnergyClass");
        RecordSet newEnerClass = AchieveHandler.getNewEnergyClassList();
        request.setAttribute("newenergyclass", newEnerClass);
        
        try{
        	forward("/membercenter/market/selloneselfInfo.jsp");
        } catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServletException ex){
			ex.printStackTrace();
		}
    }
    
    /**
     * 根据uuid获取指定投融资项目的详细信息
     * 
     * @param request
     * @param response
     */
    public void investShow(HttpServletRequest request,HttpServletResponse response)
    {
    	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        MarketHandler markethandler = new MarketHandler();
        String uuid = requestKit.getParameter("uuid", "");
        
        Record investInfo = markethandler.getInvestById(uuid);
        request.setAttribute("investInfo", investInfo);
        
        //RecordSet newEnerClass = markethandler.getFildOption("common","NewEnergyClass");
        RecordSet newEnerClass = AchieveHandler.getNewEnergyClassList();
        request.setAttribute("newenergyclass", newEnerClass);
        
        try{
        	forward("/membercenter/market/investInfo.jsp");
        } catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServletException ex){
			ex.printStackTrace();
		}
    }
    
    
    /**
     * 根据uuid获取指定技术需求的详细信息，技术市场查看页面
     * 
     * @param request
     * @param response
     */
    public void techneedView(HttpServletRequest request,HttpServletResponse response)
    {
    	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        MarketHandler markethandler = new MarketHandler();
        String uuid = requestKit.getParameter("uuid", "");
        
        Record techneedInfo = markethandler.getTechneedById(uuid);
        request.setAttribute("techneedInfo", techneedInfo);
        
        //RecordSet newEnerClass = markethandler.getFildOption("common","NewEnergyClass");
        RecordSet newEnerClass = AchieveHandler.getNewEnergyClassList();
        request.setAttribute("newenergyclass", newEnerClass);
        
        try{
        	forward("/membercenter/market/techneedView.jsp");
        } catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServletException ex){
			ex.printStackTrace();
		}
    }
    
    /**
     * 根据uuid获取指定自荐项目的详细信息，技术市场查看页面
     * 
     * @param request
     * @param response
     */
    public void selloneselfView(HttpServletRequest request,HttpServletResponse response)
    {
    	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        MarketHandler markethandler = new MarketHandler();
        String uuid = requestKit.getParameter("uuid", "");
        
        Record selloneselfInfo = markethandler.getSelloneselfById(uuid);
        request.setAttribute("selloneselfinfo", selloneselfInfo);
        
        //RecordSet newEnerClass = markethandler.getFildOption("common","NewEnergyClass");
        RecordSet newEnerClass = AchieveHandler.getNewEnergyClassList();
        request.setAttribute("newenergyclass", newEnerClass);
        
        try{
        	forward("/membercenter/market/selloneselfView.jsp");
        } catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServletException ex){
			ex.printStackTrace();
		}
    }
    
    /**
     * 根据uuid获取指定投融资项目的详细信息，技术市场查看页面
     * 
     * @param request
     * @param response
     */
    public void investView(HttpServletRequest request,HttpServletResponse response)
    {
    	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        MarketHandler markethandler = new MarketHandler();
        String uuid = requestKit.getParameter("uuid", "");
        
        Record investInfo = markethandler.getInvestById(uuid);
        request.setAttribute("investInfo", investInfo);
        
        //RecordSet newEnerClass = markethandler.getFildOption("common","NewEnergyClass");
        RecordSet newEnerClass = AchieveHandler.getNewEnergyClassList();
        request.setAttribute("newenergyclass", newEnerClass);
        
        try{
        	forward("/membercenter/market/investView.jsp");
        } catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServletException ex){
			ex.printStackTrace();
		}
    }
    
    
    /**
     * 删除技术需求信息
     * 
     * @param request
     * @param response
     */
    public void techneedDelete(HttpServletRequest request,HttpServletResponse response)
    {
    	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        MarketHandler markethandler = new MarketHandler();
        
        String uuids = requestKit.getParameter("uuids", "");
        String uuid[] = uuids.split(",");
        if(uuid!=null && uuid.length>0){
        	for(int i=0;i<uuid.length;i++){
        		//逐一对审批的信息进行审批状态的改变
        		markethandler.techneedDelete(uuid[i]);
        	}
        }
    }
    /**
     * 删除自荐项目需求信息
     * 
     * @param request
     * @param response
     */
    public void selloneselfDelete(HttpServletRequest request,HttpServletResponse response)
    {
    	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        MarketHandler markethandler = new MarketHandler();
        
        String uuids = requestKit.getParameter("uuids", "");
        
        String uuid[] = uuids.split(",");
        if(uuid!=null && uuid.length>0){
        	for(int i=0;i<uuid.length;i++){
        		//逐一对审批的信息进行审批状态的改变
        		markethandler.selloneselfDelete(uuid[i]);
        	}
        }
    }
    
    /**
     * 删除自荐项目需求信息
     * 
     * @param request
     * @param response
     */
    public void investDelete(HttpServletRequest request,HttpServletResponse response)
    {
    	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        MarketHandler markethandler = new MarketHandler();
        
        String uuids = requestKit.getParameter("uuids", "");
        String ifrecommend = requestKit.getParameter("recommend", "0");
        
        String uuid[] = uuids.split(",");
        if(uuid!=null && uuid.length>0){
        	for(int i=0;i<uuid.length;i++){
        		//逐一对审批的信息进行审批状态的改变
        		markethandler.investDelete(uuid[i]);
        	}
        }
    }
    
    
    /**
     * 获取推荐到首页的技术需求信息
     * 
     * @param request
     * @param response
     */
    public void techneedHomepageShow(HttpServletRequest request,HttpServletResponse response)
    {
    	
    	try {
			MarketShowHandler markethandler = new MarketShowHandler();
	        RecordSet techneedSet = markethandler.getTechneedHomepageShow();
	        
	        appendString(techneedSet.getJsonString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
    }
    
    /**
     * 获取推荐到首页的自荐项目信息
     * 
     * @param request
     * @param response
     */
    public void selloneselfHomepageShow(HttpServletRequest request,HttpServletResponse response)
    {
    	
    	try {
			MarketShowHandler markethandler = new MarketShowHandler();
	        RecordSet selloneselfSet = markethandler.getSelloneselfHomepageShow();
	        
	        appendString(selloneselfSet.getJsonString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
    }
    
    /**
     * 获取首页展现的投融资信息
     * 
     * @param request
     * @param response
     */
    public void investHomepageShow(HttpServletRequest request,HttpServletResponse response)
    {
    	
    	try {
			MarketShowHandler markethandler = new MarketShowHandler();
	        RecordSet investSet = markethandler.getInvestHomepageShow();
	        
	        appendString(investSet.getJsonString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
    }
    
    
    /**
     * 获取首页推荐展现的技术需求信息
     * 
     * @param request
     * @param response
     */
    public void techneedRecommendShow(HttpServletRequest request,HttpServletResponse response)
    {
    	
    	try {
			MarketShowHandler markethandler = new MarketShowHandler();
	        RecordSet techneedSet = markethandler.getTechneedRecommendShow();
	        
	        appendString(techneedSet.getJsonString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
    }
    
    /**
     * 获取首页推荐展现的自荐项目信息
     * 
     * @param request
     * @param response
     */
    public void selloneselfRecommendShow(HttpServletRequest request,HttpServletResponse response)
    {
    	
    	try {
			MarketShowHandler markethandler = new MarketShowHandler();
	        RecordSet selloneselfSet = markethandler.getSelloneselfRecommendShow();
	        
	        appendString(selloneselfSet.getJsonString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
    }
    
    /**
     * 获取首页推荐展现的投融资信息
     * 
     * @param request
     * @param response
     */
    public void investRecommendShow(HttpServletRequest request,HttpServletResponse response)
    {
    	
    	try {
			MarketShowHandler markethandler = new MarketShowHandler();
	        RecordSet investSet = markethandler.getInvestRecommendShow();
	        
	        appendString(investSet.getJsonString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
    }
    
    
    

    /**
     * 根据uuid获取指定技术需求的详细信息，技术市场查看页面。前台查询展现用，非登录即可查看
     * 
     * @param request
     * @param response
     */
    public void techneedInfoView(HttpServletRequest request,HttpServletResponse response)
    {
    	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        MarketHandler markethandler = new MarketHandler();
        String uuid = requestKit.getParameter("uuid", "");
        
        Record techneedInfo = markethandler.getTechneedById(uuid);
        request.setAttribute("techneedInfo", techneedInfo);
        
        //RecordSet newEnerClass = markethandler.getFildOption("common","NewEnergyClass");
        RecordSet newEnerClass = AchieveHandler.getNewEnergyClassList();
        request.setAttribute("newenergyclass", newEnerClass);
        
        try{
        	forward("/market/techneedinfo.jsp");
        } catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServletException ex){
			ex.printStackTrace();
		}
    }
    
    /**
     * 根据uuid获取指定自荐项目的详细信息，技术市场查看页面。前台查询展现用，非登录即可查看
     * 
     * @param request
     * @param response
     */
    public void selloneselfInfoView(HttpServletRequest request,HttpServletResponse response)
    {
    	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        MarketHandler markethandler = new MarketHandler();
        String uuid = requestKit.getParameter("uuid", "");
        
        Record selloneselfInfo = markethandler.getSelloneselfById(uuid);
        request.setAttribute("selloneselfInfo", selloneselfInfo);
        
        //RecordSet newEnerClass = markethandler.getFildOption("common","NewEnergyClass");
        RecordSet newEnerClass = AchieveHandler.getNewEnergyClassList();
        request.setAttribute("newenergyclass", newEnerClass);
        
        try{
        	forward("/market/selloneselfinfo.jsp");
        } catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServletException ex){
			ex.printStackTrace();
		}
    }
    
    /**
     * 根据uuid获取指定投融资项目的详细信息，技术市场查看页面。前台查询展现用，非登录即可查看
     * 
     * @param request
     * @param response
     */
    public void investInfoView(HttpServletRequest request,HttpServletResponse response)
    {
    	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        MarketHandler markethandler = new MarketHandler();
        String uuid = requestKit.getParameter("uuid", "");
        
        Record investInfo = markethandler.getInvestById(uuid);
        request.setAttribute("investInfo", investInfo);
        
        //RecordSet newEnerClass = markethandler.getFildOption("common","NewEnergyClass");
        RecordSet newEnerClass = AchieveHandler.getNewEnergyClassList();
        request.setAttribute("newenergyclass", newEnerClass);
        
        try{
        	forward("/market/investinfo.jsp");
        } catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ServletException ex){
			ex.printStackTrace();
		}
    }
    
    
    /**
     * 按条件检索科技市场信息。
     * 
     * @param request
     * @param response
     */
    public void marketSearch(HttpServletRequest request,HttpServletResponse response)
    {
    	
			try {
				MarketHandler markethandler = new MarketHandler();
				RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
		        PagingInfo pagingInfo = new PagingInfo(request, 10, "^(?!.*(result)|(LTPAToken)).*$");
		        
		        String infotype= requestKit.getParameter("infotype", "");
		        String infoclass = requestKit.getParameter("infoclass", "");
		        String publishdate = requestKit.getParameter("publishdate", "");
		        
		        Date today = new Date(System.currentTimeMillis());
		        
		        String searchday = "";
		        
		        if(!"".equals(publishdate)){
		        	//如果需要根据日期判断，则打印日期
		        	if("1".equals(publishdate)){//一周
		        		searchday = markethandler.getCalculateDate(0, 0, -7);		        		
		        	}else if("2".equals(publishdate)){//一月
		        		searchday = markethandler.getCalculateDate(0, -1, 0);		        		
		        	}else if("3".equals(publishdate)){//三个月
		        		searchday = markethandler.getCalculateDate(0, -3, 0);		        		
		        	}else if("4".equals(publishdate)){//半年
		        		searchday = markethandler.getCalculateDate(0, -6, 0);		        		
		        	}else if("5".equals(publishdate)){//一年
		        		searchday = markethandler.getCalculateDate(-1, 0, 0);		        		
		        	}
		        }
		        
		        String forwardurl = "";
		        RecordSet resultSet = null;
		        
		        if("1".equals(infotype)){
		        	//技术需求
		        	resultSet = markethandler.getTechneedByCondition(infoclass, searchday, pagingInfo);
		        }else if("2".equals(infotype)){
		        	//自荐项目
		        	resultSet = markethandler.getSelloneselfByCondition(infoclass,searchday, pagingInfo);
		        }else{
		        	//投融资项目
		        	resultSet = markethandler.getInvestByCondition(infoclass,searchday, pagingInfo);
		        }
		        
		        request.setAttribute("resultSet", resultSet);
		        request.setAttribute("pagingInfo", pagingInfo);
		        request.setAttribute("infoclass", infoclass);
		        request.setAttribute("infotype", infotype);
		        request.setAttribute("publishdate", publishdate);
		        
		    	forward("/market/marketsearchresult.jsp");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ServletException ex){
				ex.printStackTrace();
			}
		
    }
}


